﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessLogic
{
    public class PicLogic
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemId"></param>
        /// <param name="SourceType"></param>
        /// <returns></returns>
        public List<T_Pic> GetPicListByTypeAndSource(int itemId, int SourceType)
        {
            Model1Container db = new Model1Container();;
            List<T_Pic> list = db.T_Pic.Where(c => c.SouceID == itemId && c.Type == SourceType).ToList();
            return list;
        }
        public void DeletePic(string Url)
        {
            Model1Container db = new Model1Container();
            var tem = db.T_Pic.Where(c => c.Url == Url);
            if (tem == null || tem.Count() == 0)
                return;
            var category = tem.First();
            db.T_Pic.Remove(category);
            db.SaveChanges();
        }
        public int AddPic(T_Pic Pic)
        {
            int result = 0;
            using (Model1Container db = new Model1Container())
            {
                db.T_Pic.Add(Pic);
                result = db.SaveChanges();
            }
            return result;
        }
    }
}
